package assdraw2.coloragent.presentation;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import assdraw2.coloragent.ColorControl;
import assdraw2.common.MessageType;
import assdraw2.common.PACMessage;
import assdraw2.common.PresentationWindowListener;

public class ColorPresentation extends JFrame{
	
	private static final long serialVersionUID = 1L;

	private ColorControl control;

	public ColorPresentation(ColorControl control) {
		super("Color");
		this.control = control;

		setResizable(false);
		//setLayout(new GridLayout(1, 1));
		setLayout(new FlowLayout());
		
		initComponents();
		
		this.setPreferredSize(new Dimension(200, 150));
		this.pack();
		setLocation(500,100);
		this.setVisible(true);
		
		addWindowListener(new PresentationWindowListener(control));
	}


	private void initComponents() {

        JPanel colorPanel = new JPanel();
        colorPanel.setBorder(BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        colorPanel.setLayout(new GridLayout(4,1));
        ButtonGroup colors = new ButtonGroup();
        
        JRadioButton color1 = new JRadioButton("Blue");
        color1.setActionCommand("Blue");
        color1.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				control.sendMessage(new PACMessage(MessageType.COLOR, control, Color.BLUE));
			}
        	
        });
        
        JRadioButton color2 = new JRadioButton("Green");
        color2.setActionCommand("Green");
        color2.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				control.sendMessage(new PACMessage(MessageType.COLOR, control, Color.GREEN));
				
			}
        	
        });
        
        JRadioButton color3 = new JRadioButton("Black");
        color3.setSelected(true);
        color3.setActionCommand("Black");
        color3.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				control.sendMessage(new PACMessage(MessageType.COLOR, control, Color.BLACK));
				
			}
        	
        });
        
        JRadioButton color4 = new JRadioButton("Pink");
        color4.setActionCommand("Pink");
        color4.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				control.sendMessage(new PACMessage(MessageType.COLOR, control, Color.PINK));
				
			}
        	
        });
        
        colors.add(color1);
        colors.add(color2);
        colors.add(color3);
        colors.add(color4);
        
        colorPanel.add(color1);
        colorPanel.add(color2);
        colorPanel.add(color3);
        colorPanel.add(color4);

        add(colorPanel);
		
	}


}
